//
//  MyCircularProgressWithShape.swift
//  SwiftUIShape
//
//  Created by 李煜 on 2024/7/31.
//

import SwiftUI

struct MyCircularProgressWithShape: View {
  private var purpleGradient = LinearGradient(gradient: Gradient(colors: [Color(red: 207 / 255, green: 150 / 255, blue: 207 / 255), Color(red: 107 / 255, green: 116 / 255, blue: 179 / 255)]), startPoint: .trailing, endPoint: .leading)
  var prog: CGFloat = 0.85
  
  var body: some View {
    ZStack {
      Circle()
        .stroke(Color(.systemGray6), lineWidth: 20)
        .frame(width: 300, height: 300)
        .overlay {
          Path { p in
            p.addArc(center: CGPoint(x: 150, y: 150), radius: 150, startAngle: .degrees(0), endAngle: .degrees(360 * prog), clockwise: false)
          }
          .stroke(purpleGradient, lineWidth: 20)
          // 进度文字
          .overlay {
            VStack {
              Text("\(String(format: "%.0f", prog * 100))%")
                .font(.system(size: 50, weight: .black, design: .rounded))
              Text("Compelete")
                .fontDesign(.rounded)
                .font(.system(size: 25))
                .fontWeight(.regular)
            }
          }
        }
    }
    .padding()
  }
}

#Preview {
  MyCircularProgressWithShape()
}
